//
//  ERField.h
//  metadata
//
//  Created by easy on 11-5-30.
//  Copyright 2011 zeasy@qq.com. All rights reserved.
//
 
#import "ERuntime.h" 

// ERContext 环境下的Field(ivar)
@interface ERField : NSObject {
	ERFieldEntity *entity;
	Ivar source;
	int offset;
}
//@property (nonatomic, readonly) entity;			不可读
@property (nonatomic, readonly) Ivar source;				//field 源数据
@property (nonatomic, readonly) NSString *name;				//field 名
@property (nonatomic, readonly) ERClassType *classType;		//field 类类型
@property (nonatomic, readonly) int offset;					//偏移量
@property (nonatomic, readonly) NSUInteger size;			//sizeof(source)
@property (nonatomic, readonly) NSUInteger alignment;		//align,如果addIvar 需要log2(alignment)

#pragma mark init
-(id) initWithIvar:(Ivar) ivar;

#pragma mark objc runtime at object_ 
//如果需要调用以下方法，[必须]检测 classType 是否是对应的类型
//非对象类型的数据均是通过指针(void *)来获取和设置，这会导致在不同类型的数据转换出错
//如：如果先调用 setFloatValue:1.0f 然后 doubleValue 得到值可能不一样
//如果需要设置或获取其它类型，如枚举，联合，long long等等其它类型，使用 pointerValueAt 和 setPointerValue:at:
-(id) valueAt:(id) object;								//得到object的本field值
-(void) setValue:(id)value at:(id) object;				//设置object的本field值
-(void *) pointerValueAt:(id) object;					//得到object中本field值的指针
-(void) setPointerValue:(void *)value at:(id) object;	//设置object中本field值的指针
-(int) intValueAt:(id) object;							//根据指针返回int值
-(void) setIntValue:(int) value at:(id) object;			//设置指针为int值
-(BOOL) boolValueAt:(id) object;						//返回bool值
-(void) setBoolValue:(BOOL) value at: (id) object;		//设置bool值
-(char) charValueAt:(id) object;                                                                        //返回char值
-(void) setCharValue:(char) value at: (id) object;		//设置char值
-(short) shortValueAt:(id) object;						//返回short值
-(void) setShortValue:(short) value at:(id) object;		//设置short值
-(float) floatValueAt:(id) object;                                                                      //返回float值
-(void) setFloatValue:(float) value at:(id) object;		//设置float值
-(double) doubleValueAt:(id) object;					//返回double值
-(void) setDoubleValue:(double) value at:(id) object;	//设置double值
-(long) longValueAt:(id) object;						//返回long值
-(void) setLongValue:(long) value at:(id) object;		//设置long值
@end

 
@interface ERFieldEntity : NSObject{
	ERClassType *classType;
	NSString *name;
}
@property (nonatomic, retain) ERClassType *classType;		//变量类类型
@property (nonatomic, retain) NSString *name;				//变量名

#pragma mark init
-(id) initWithName:(NSString *) aName type:(ERClassType *) type;
+(id) entityWithIvar:(Ivar) var;						//ivar的变量实体

+(id) entityWithName:(NSString *) aName type:(ERClassType *) type;

+(id) entityWithName:(NSString *) aName fromClass:(Class) clazz;	//Class型变量实体
+(id) entityWithName:(NSString *) aName fromERClass:(ERClass *) erClazz;//ERClass型变量实体


+(id) intEntityWithName:(NSString *) aName;				//int型变量实体
+(id) charEntityWithName:(NSString *) aName;			//char型变量实体
+(id) boolEntityWithName:(NSString *) aName;			//bool型变量实体
+(id) shortEntityWithName:(NSString *) aName;			//short型变量实体
+(id) longEntityWithName:(NSString *) aName;			//long型变量实体
+(id) floatEntityWithName:(NSString *) aName;			//float型变量实体
+(id) doubleEntityWithName:(NSString *) aName;			//double型变量实体
@end
 
